# -*- coding:utf-8 -*-
import sqlite3
import random
from datetime import datetime, timedelta

def generate_test_data(db_name='test.db', count=1000):
    conn = sqlite3.connect(db_name)
    cursor = conn.cursor()

    # 创建测试表
    cursor.execute('''
    CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY,
        name TEXT,
        age INTEGER,
        email TEXT,
        created_at TEXT,
        score REAL
    )
    ''')

    # 生成测试数据
    names = ['张三', '李四', '王五', '赵六', '钱七', '孙八', '周九', '吴十']
    domains = ['qq.com', '163.com', 'gmail.com', 'outlook.com']
    base_date = datetime.now()

    for i in range(count):
        name = random.choice(names)
        age = random.randint(18, 60)
        email = f"{name}{random.randint(100, 999)}@{random.choice(domains)}"
        created_at = (base_date - timedelta(days=random.randint(0, 365))).strftime('%Y-%m-%d %H:%M:%S')
        score = round(random.uniform(60, 100), 2)
        
        cursor.execute(
            'INSERT INTO users (name, age, email, created_at, score) VALUES (?, ?, ?, ?, ?)',
            (name, age, email, created_at, score)
        )

    conn.commit()
    conn.close()

if __name__ == "__main__":
    generate_test_data()
    print("测试数据生成完成！")